package cn.iocoder.yudao.module.of.service.userremindsetup;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.of.controller.admin.userremindsetup.vo.*;
import cn.iocoder.yudao.module.of.dal.dataobject.userremindsetup.UserRemindSetupDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.of.dal.mysql.userremindsetup.UserRemindSetupMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.of.enums.ErrorCodeConstants.*;

/**
 * 日程提醒设置 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class UserRemindSetupServiceImpl implements UserRemindSetupService {

    @Resource
    private UserRemindSetupMapper userRemindSetupMapper;

    @Override
    public Long createUserRemindSetup(UserRemindSetupSaveReqVO createReqVO) {
        // 插入
        UserRemindSetupDO userRemindSetup = BeanUtils.toBean(createReqVO, UserRemindSetupDO.class);
        userRemindSetupMapper.insert(userRemindSetup);
        // 返回
        return userRemindSetup.getId();
    }

    @Override
    public void updateUserRemindSetup(UserRemindSetupSaveReqVO updateReqVO) {
        // 校验存在
        validateUserRemindSetupExists(updateReqVO.getId());
        // 更新
        UserRemindSetupDO updateObj = BeanUtils.toBean(updateReqVO, UserRemindSetupDO.class);
        userRemindSetupMapper.updateById(updateObj);
    }

    @Override
    public void deleteUserRemindSetup(Long id) {
        // 校验存在
        validateUserRemindSetupExists(id);
        // 删除
        userRemindSetupMapper.deleteById(id);
    }

    private void validateUserRemindSetupExists(Long id) {
        if (userRemindSetupMapper.selectById(id) == null) {
            throw exception(USER_REMIND_SETUP_NOT_EXISTS);
        }
    }

    @Override
    public UserRemindSetupDO getUserRemindSetup(Long id) {
        return userRemindSetupMapper.selectById(id);
    }

    @Override
    public PageResult<UserRemindSetupDO> getUserRemindSetupPage(UserRemindSetupPageReqVO pageReqVO) {
        return userRemindSetupMapper.selectPage(pageReqVO);
    }

}